package com.sqstudio.control
{
	import com.sqstudio.common.DataProxy;
	import com.sqstudio.common.LunarCalendar;
	import com.sqstudio.common.Sys;
	import com.sqstudio.event.CalendarEvent;
	import com.sqstudio.model.Model;
	import com.sqstudio.view.DescPanel;
	
	import flash.events.Event;

	public class DescController
	{
		private var _descPanel:DescPanel;
		public function DescController()
		{
			this._descPanel = new DescPanel();
			Sys.STAGE.addChild(this._descPanel);
			this._descPanel.x = 409;
			this._descPanel.y = 117.5;
			
			CalendarEvent.Dispatcher.addEventListener(CalendarEvent.DATE_CHANGE,dateChangeHandler);
		}
		
		private function dateChangeHandler(e:Event):void
		{
			var lc:LunarCalendar = new LunarCalendar(Model.CrtDate);
			
			var gong:String = lc.getGYear()+"-"+checkNum(lc.getGMonth()+1)+"-"+checkNum(lc.getGDate())+" 星期"+lc.getGrDay();
			var fsvArr:Array = DataProxy.checkNextHoliday(Model.CrtDate);
			var fsv:String =  fsvArr[1]==0?"今天是"+fsvArr[0]:"距"+fsvArr[0]+"还有"+fsvArr[1]+"天";
			var num:String = String(lc.getGDate());
			var nong:String ="农历 "+lc.getCnMonth()+" "+lc.getCnDay()+"\n"+lc.getCnYear()+"年 "+
				lc.getGZMonth()+"月\n"+lc.getGZDate()+"日";
			this._descPanel.updateData([gong,fsv,num,nong]);
		}		
		
		private function checkNum(value:int):String{
			var str:String = String(value);
			if(value<10){
				str ="0"+str; 
			}
			return str;
		}
	}
}